#pragma once

#include <config.h>
#include <gl/glew.h>
#include <gl/wglew.h>

// ( enum val ) pair list  multi map
template <typename KeyType, typename ValueType>
class AttribSetT
{	
public:	
	typedef AttribSetT<KeyType, ValueType> SelfType;
	
	std::vector<KeyType> vAttribKeys;
	std::vector<ValueType> vAttribValues;
	KeyType m_badKey;
	ValueType m_defaultValue;

	SelfType& SetDefaultValue(const ValueType& defaultVal){ m_defaultValue = defaultVal; return *this; }
	SelfType& SetBadKey(const KeyType& badkey){ m_badKey = badkey; return *this; }
	
	//AttribSetT(){}
	AttribSetT(const KeyType& badkey, const ValueType&defaultVal){ m_badKey = badkey; m_defaultValue = defaultVal; }

	SelfType& reserve(int nCnt){ vAttribKeys.reserve(nCnt); vAttribValues.reserve(nCnt); return *this; }
	
	typedef std::pair<KeyType, ValueType> ItemType;
	ItemType at(int idx)const{ return ItemType(vAttribKeys[idx], vAttribValues[idx]); }
	size_t size()const
	{
		assert(vAttribKeys.size() == vAttribValues.size());
		return vAttribKeys.size();
	}

	ValueType& operator[](const KeyType& key){
		int ipos = get_attrib_ipos(key);
		if(ipos < 0){			
			vAttribKeys.push_back(key);
			vAttribValues.resize(vAttribKeys.size(), m_defaultValue);
			return *vAttribValues.rbegin();
		}
		else
			return vAttribValues[ipos];
	}	

	int get_attrib_ipos(const KeyType& key)const 
	{
		for(int i=0;i<(int)size();++i){
			if(key == vAttribKeys[i])
				return i;
		}
		return -1;
	}

	KeyType* GetKeys(){ return &vAttribKeys.front(); }
	ValueType* GetValues(){ return &vAttribValues.front(); }
	const KeyType* GetKeys()const{ return &vAttribKeys.front(); }
	const ValueType* GetValues()const{ return &vAttribValues.front(); }

};

/************************************************************************/
//valid attributes are:
//
/************************************************************************/
class Win32oglPixelFormat
{
public:
	typedef AttribSetT<GLenum,int> iAttribSetType;
	typedef AttribSetT<GLenum,float> fAttribSetType;
	Win32oglPixelFormat();
	
	std::vector<int> m_viAttribs;
	std::vector<float> m_vfAttribs;


	void invalidate();
	int* GetviAttribs(){ return &m_viAttribs.front(); }
	float* GetvfAttribs(){ return &m_vfAttribs.front(); }
	const int* GetviAttribs()const{ return &m_viAttribs.front(); }
	const float* GetvfAttribs()const{ return &m_vfAttribs.front(); }

	iAttribSetType m_iAttribSet;
	fAttribSetType m_fAttribSet;
};
